/**
 * 登录验证(前后端+数据库)
 */
const express = require("express");
const app = express();
const bp = require('body-parser')
const db = require('./db.js')

app.use(bp.urlencoded({ extended: false }))
app.use(express.static('login'));

app.post('/login', (req, res) => {
  let reqData = req.body;
  let sql = "select count(*) as total from user where username=? and password=?"
  let data = [reqData.username, reqData.password]
  console.log(data);
  db.base('user',sql, data, (result) => {
    if(result[0].total != 0){
      res.send('登陆成功')
    }else{
      res.send('登录失败')
    }
  })
})
app.listen(9999, () => {
  console.log("gogogo");
})
